package core;

import gitobject.*;
import java.io.File;

public class JitCatFile {
    /**
     * view content of a tree
     */
    public static void catFileTree(String objectKey)throws Exception {
        if (objectExist(objectKey)) {
            Tree tree = Tree.deserialize(objectKey);
            System.out.println(tree.getValue());
        } else
            System.out.println(objectKey + " did not match any objects");
    }
    /**
     * view content of a blob
     */
    public static void catFileBlob(String objectKey)throws Exception {
        if (objectExist(objectKey)) {
            Blob blob = Blob.deserialize(objectKey);
            System.out.println(blob.getValue());
        } else
            System.out.println(objectKey + " did not match any objects");
    }
    /**
     * view content of a commit
     */
    public static void catFileCommit(String objectKey)throws Exception{
        if (objectExist(objectKey)) {
            Commit commit = Commit.deserialize(objectKey);
            System.out.println(commit.getValue());
        } else
            System.out.println(objectKey + " did not match any objects");
    }
    /**
     * return if an object exist
     */
    public static boolean objectExist(String objectKey){
        File file = new File(GitObject.getPath() + File.separator + objectKey);
        return file.exists();
    }
}
